#include"rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"
#include "std_msgs/msg/bool.hpp"
#include"std_msgs/msg/int32.hpp"
using namespace std::chrono_literals;
using std::placeholders::_1;
int a[2004]={0,1,1};
int fb(size_t b){
    for(size_t i=3;i<=b;i++){
        a[i]=a[i-1]+a[i-2];
    }
    return a[b];
}
class node2:public rclcpp::Node{
    public:
    node2():Node("node2"),count_(1){
        puber2_=this->create_publisher<std_msgs::msg::Int32>("fb",10);
        timer_=this->create_wall_timer(1ms,std::bind(&node2::time_callback,this));
        suber2_=this->create_subscription<std_msgs::msg::Bool>("osb",10,std::bind(&node2::sub2_callback,this,_1));
    }
    private:
    rclcpp::Publisher<std_msgs::msg::Int32>::SharedPtr puber2_;
    rclcpp::Subscription<std_msgs::msg::Bool>::SharedPtr suber2_;
    void sub2_callback(const std_msgs::msg::Bool &msg)const{
        if(msg.data){
            RCLCPP_INFO(this->get_logger(),"True");
        }
        else  RCLCPP_INFO(this->get_logger(),"False");
    }
    void time_callback(){
        auto message=std_msgs::msg::Int32();
        if(a[count_]){
            message.data=a[count_];
            puber2_->publish(message);
            count_++;
            if(a[count_]>=12345&&a[count_]){
                count_=1;
                return;
            }
        }
        else {
             if(fb(count_)>=12345)count_=1;
        message.data=fb(count_);
        puber2_->publish(message);
        count_++;
        }
       
        
    }
    rclcpp::TimerBase::SharedPtr timer_;
    size_t count_;
};
int main(int argc,char* argv[]){
    rclcpp::init(argc,argv);
    rclcpp::spin(std::make_shared<node2>());
    rclcpp::shutdown();
    return 0;

}